package com.sanjiahantang.youjiaclient.module.common.presenters;

import android.content.Context;

import com.sanjiahantang.youjiaclient.base.BaseMvpPresenter;
import com.sanjiahantang.youjiaclient.base.BaseView;
import com.sanjiahantang.youjiaclient.base.CallBack;
import com.sanjiahantang.youjiaclient.module.common.beans.HelpBean;
import com.sanjiahantang.youjiaclient.module.common.models.IUserModel;
import com.sanjiahantang.youjiaclient.module.common.models.impl.UserModel;

import java.util.HashMap;
import java.util.Map;

import static com.sanjiahantang.youjiaclient.config.StaticValue.RESPONSE_CODE_SUC;

/**
 * Created by zy on 2017/10/17.
 */

public class WebPresenter extends BaseMvpPresenter<BaseView> {

    private IUserModel userModel;
    public WebPresenter(){
        userModel = new UserModel();
    }
    public void loadHelpArticle(Context context, int id, final BaseView.OnLoadListener onLoadListener) {
        Map<String,String> param = new HashMap<>();
        param.put("articleNo",String.valueOf(id));
        userModel.loadHelpArticle(context,param,new CallBack<HelpBean>(){

            @Override
            public void onSuccess(HelpBean response, Context context, Object tag) {
                hideProgress();
                if (response.getCode() == RESPONSE_CODE_SUC && response.getItem() != null){
                    onLoadListener.onLoad(response.getItem());
                }

            }

            @Override
            public void onFailure(String message) {
                hideProgress();
            }
        });
    }

    private void hideProgress() {
        if (mView != null) mView.hideProgress();
    }
}
